package com.voquanghoa.com.sudokumaster.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;

import com.voquanghoa.com.sudokumaster.R;
import com.voquanghoa.com.sudokumaster.controllers.SudokuCellView;

/**
 * Created by Vo Quang Hoa on 12/30/2014.
 */
public class SudokuCellAdapter extends BaseAdapter {
	private Context mContext;

	public static int SudokuCellHeight = 0;
	public static int SudokuCellWidth = 0;
	private SudokuCellView[] _sudokuCells;
	public SudokuCellAdapter(Context c) {
		mContext = c;
		_sudokuCells = new SudokuCellView[81];
	}
	public int getCount() {
		return 81;
	}
	public Object getItem(int position) {
		return null;
	}
	public long getItemId(int position) {
		return 0;
	}
	public View getView(int position, View convertView, ViewGroup parent) {
		SudokuCellView sudokuCell = null;

		if(convertView == null){
			convertView = View.inflate(mContext, R.layout.sudoku_cell,null);
		}

		sudokuCell = (SudokuCellView) convertView;
		sudokuCell.SetNumber(position);

		sudokuCell.findViewById(R.id.lin).setLayoutParams(new AbsListView.LayoutParams(SudokuCellWidth, SudokuCellHeight));
		_sudokuCells[position]=sudokuCell;
		return  sudokuCell;
	}
	public void updateCellsSize(){
		AbsListView.LayoutParams layout = new AbsListView.LayoutParams(SudokuCellWidth, SudokuCellHeight);
		for(int i=0;i<_sudokuCells.length;i++){
			if(_sudokuCells[i]!=null){
				_sudokuCells[i].setLayoutParams(layout);
			}
		}
	}
}
